package com.example.tuter.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.tuter.R;
import com.example.tuter.activity.MyCollectActivity;
import com.example.tuter.activity.MyPostActivity;
import com.example.tuter.activity.SettingsActivity;
import com.example.tuter.activity.UpdateUserInfoActivity;
import com.example.tuter.entity.UserInfo;
import com.example.tuter.util.Constant;
import com.example.tuter.util.SPUtils;


public class FragmentMine extends BaseFragment {
    String TAG = "run_fragment_mine";
    private TextView username, tutName;
    private LinearLayout setting, myCollect, myPost, updateUsername;
    private UserInfo userInfo = null;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        return inflater.inflate(R.layout.fragment_mine, container, false);
    }

    @Override
    protected void initData() {
        this.userInfo = SPUtils.getUserInfo(getContext());
    }

    @Override
    protected void bindEvent() {
        //设置更新用户信息
        updateUsername.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), UpdateUserInfoActivity.class);
                startActivity(intent);
            }
        });

        setting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), SettingsActivity.class);
                startActivity(intent);
            }
        });
        myCollect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), MyCollectActivity.class);
                startActivity(intent);
            }
        });
        myPost.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), MyPostActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void initView(View view) {
        setting = getActivity().findViewById(R.id.mine_setting);
        myCollect = getActivity().findViewById(R.id.mine_mycollect);
        myPost = getActivity().findViewById(R.id.mine_mytie);
        username = getActivity().findViewById(R.id.mine_username);

        username.setText(userInfo == null ? Constant.NOTLOGINSTRING : userInfo.getUsername());//设置用户昵称
        tutName = getActivity().findViewById(R.id.mine_tutname);
        tutName.setText(userInfo == null ? Constant.NOTLOGINSTRING : userInfo.getAcademyName());//设置学院昵称
        updateUsername = getActivity().findViewById(R.id.imageview_mine_update_username);
    }

    @Override
    protected int getLayoutID() {
        return R.layout.fragment_mine;
    }




    @Override
    public void onResume() {
        super.onResume();
        if (userInfo != null) {
            username.setText(userInfo.getUsername());
            tutName.setText(userInfo.getAcademyName());
        }
    }

}
